package Sequence;

public class Test0738 {
}

class Solution0738_1 {
    public int monotoneIncreasingDigits(int n) {
        char[] chars = (n + "").toCharArray();
        int len = chars.length, start = len;
        for (int i = len-1;i>0; i--){
            if(chars[i-1]>chars[i]){
                chars[i-1]--;
                start = i;
            }
        }

        for (int i = start; i < len; i++) {
            chars[i]='9';
        }
        return Integer.parseInt(new String(chars));
    }
}
